package pl.edu.uj.ii.battleships.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import pl.edu.uj.ii.battleships.activities.CustomActivity;

import android.content.Context;
import android.content.res.AssetManager;

public class ConfigPropsManager {
	
	CustomActivity act;
	
	public ConfigPropsManager(CustomActivity activity){
		act = activity;
	}

	public String getValue(String prop, String default_value){
		AssetManager assetManager = act.getResources().getAssets();
		Properties pp = new Properties();
		InputStream isConfig = null;
		try {
			isConfig = assetManager.open("config.properties",Context.MODE_PRIVATE);
			pp.load(isConfig);
			return pp.getProperty(prop, default_value);
		} catch (IOException e) {
			Logger.error("Failed to read config.props", e);
		} finally {
			try {
				if(isConfig != null)
					isConfig.close();
			} catch (IOException e) {
				Logger.error("Unexpected exception while reading config.props", e);
			}
		}
		return null;
	}
	
}
